import com.sun.org.apache.xpath.internal.objects.XNull;

import java.util.Scanner;

public class GessNumber {
    public static void main(String[] args) {
        //1.打印提示信息
        System.out.println("欢迎来到猜数字！");
        System.out.println("请输入一个1-100之间的答案数字");
        //2.生成一个1-100之间的答案数字

        //3.

        boolean w=true;         Scanner scan = new Scanner(System.in);
        while (w){
            int answer=(int)(Math.random()*100+1);
            boolean chances=true;
            while (chances) {
String guess1="";
                 guess1 = scan.nextLine();
                if (isNumeric(guess1)) {

                    int guess = Integer.parseInt(guess1);

                    //4.
                    if (guess > answer) {
                        System.out.println("大了");
                    } else if (guess < answer) {
                        System.out.println("小了");
                    } else {
                        System.out.println("恭喜你！猜对了！");
                        chances = false;
                    }

                }else {w=false;break;}
            }
            if (!chances) {
                System.out.println("是否重玩 y/n ");
                String g = scan.nextLine();
                System.out.println(g);
                if (g.equals("y")) {
                    w = true;System.out.println("开始游戏");
                } else if (g.equals("n")) {
                    w=false;
                }
            }
        }
    }
    public static boolean isNumeric(String str){
        for (int i = str.length();--i>=0;){
            if (!Character.isDigit(str.charAt(i))){
                return false;
            }
        }
        return true;
    }
}
